﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


//程琳 2012-11-1
namespace Microhard.Core.DBUtility
{

    /// <summary>
    /// 验证结果
    /// </summary>
    public class ValidationResult
    {
        private Dictionary<string, string> _errorMsg = new Dictionary<string, string>();
        public bool IsValid { set; get; }
        public Dictionary<string, string> ErrorMsg
        {
            set { this._errorMsg = value; }
            get { return this._errorMsg; }
        }
    }


    public class ScopeExecutedResult
    {
        public Guid PKID { set; get; }
        public Guid ResourceID { set; get; }
        public Guid OperatorID { set; get; }
        public Guid OperatorGroupID { set; get; }
        public bool IsSysManage { set; get; }
    }

    /// <summary>
    /// 执行结果
    /// </summary>
    public class ExecutedResult
    {
        public ExecutedResult()
        {
            this.Scope = new ScopeExecutedResult();
        }
        private Dictionary<string, string> _errorMsg = new Dictionary<string, string>();
        public bool IsSucceed
        {
            get { return ErrorMsg.Count == 0 ? true : false; }
        }


        public Dictionary<string, string> ErrorMsg
        {
            set { this._errorMsg = value; }
            get { return this._errorMsg; }
        }
        public string ErrorMsgTxt
        {
            get
            {
                StringBuilder error = new StringBuilder();
                foreach (var d in _errorMsg)
                {
                    error.Append(d.Value);
                }
                return error.ToString();
            }
        }
        //用于存储在数据权限表中
        public ScopeExecutedResult Scope { set; get; }
        public object ExecutedModel { set; get; }
        //工作流相关
        public Guid WorkflowInstanceID { set; get; }
        public bool CanEditBusinessSheet { set; get; }
        public OperationStatus OperationStatus { set; get; }
    }

    public enum DataCollectionScope
    {
        All = 1,            // 全部数据
        Group = 2,          // 用户所在组数据
        Self = 3,           // 自己的数据
        None = 4,           // 没有权限
        Specific = 5        // 特定的数据
    }

    public class WorkFlowWithBusID
    {
        public Guid CurrentBusID { set; get; }
        public Guid WorkflowInstanceID { set; get; }
    }

    /// <summary>
    /// 数据权限结果
    /// </summary>
    public class ScopeResult
    {
        public Guid CurrentUserID { set; get; }
        public string CurrentUserName { set; get; }
        public DataCollectionScope Scope { set; get; }
        public Guid ResourceID { set; get; }
        public string ResourceName { set; get; }
        public string ResourceKeyName { set; get; }
        public Guid OperationID { set; get; }
        public string OperationName { set; get; }
        public string OperationKeyName { set; get; }
        public List<Guid> PKID { set; get; }
        public bool IsSysManage { set; get; }
        public string ModelNameSpace { set; get; }
        public string ClassName { set; get; }
    }


    /// <summary>
    /// 业务方法
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public interface IRepository<T>
    {
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        ExecutedResult Add(T model);
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        ExecutedResult Update(T model);
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        ExecutedResult Delete(List<Guid> ids);
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        ExecutedResult Delete(T model);
        /// <summary>
        /// 根据ID获得对象
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        T GetModelByID(Guid id);
        /// <summary>
        /// 通过model获得T
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        T GetModelByModel(T model);
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="Model"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalCount"></param>
        /// <returns></returns>
        List<T> Query(T Model, int pageIndex, int pageSize, out int totalCount);
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="Model"></param>
        /// <returns></returns>
        List<T> Query(T Model);
        /// <summary>
        /// 数据范围
        /// </summary>
        ScopeResult scope { set; get; }
        /// <summary>
        /// 数据重复验证
        /// </summary>
        /// <param name="Model"></param>
        /// <returns></returns>
        //bool IsDuplicate(T Model);
    }
}
